package com.operation.controller;

import com.operation.beans.Performance;
import com.operation.beans.Result;
import com.operation.beans.YearDetailDep;
import com.operation.entity.WorkOrder;
import com.operation.service.WorkOrderService;
import com.operation.utils.FileUploadUtil;
import com.operation.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
public class WorkOrderServiceController {
    @Autowired
    WorkOrderService workOrderService;

    /**
     * 提交工单
     * @param workOrder
     */
    @RequestMapping(value = "/addWorkOrder",method = RequestMethod.POST)
    public Result addWorkOrder(@RequestBody WorkOrder workOrder){
        return workOrderService.addWorkOrder(workOrder);
    }

    /**
     * 查看工单信息
     * @param workOrder
     */
    @RequestMapping(value = "/getWorkOrderInfo",method = RequestMethod.POST)
    public Result confirmCompleteWorKOrder(@RequestBody WorkOrder workOrder){
        return workOrderService.queryWorkOrderInformation(workOrder);
    }

    /**
     * 上传工单图片
     * @param multipartFile,httpServletRequest
     */
    @RequestMapping(value = "/uploadWorkOrderPhoto/{jobNumber}",method = RequestMethod.POST)
    public Result confirmCompleteWorKOrder(@PathVariable String jobNumber,@RequestParam("file")MultipartFile multipartFile, HttpServletRequest httpServletRequest) throws IOException {
        WorkOrder workOrder = new WorkOrder();
        workOrder.setJobnumber(jobNumber);
        workOrder.setImg(FileUploadUtil.singleFileUpload(multipartFile,httpServletRequest));
        return ResultUtil.success(workOrderService.addWorkOrderPhoto(workOrder),0);
    }

    /**
     * 查看部门每月的工单数
     */
    @RequestMapping(value = "/queryOrderNumberByDetails",method = RequestMethod.POST)
    public Result confirmCompleteWorKOrder(@RequestBody YearDetailDep yearDetailDep){
        return ResultUtil.success(
                workOrderService.byDetails(yearDetailDep),
                0
        );
    }

    /**
     * 删除工单
     * @param workOrder
     * @return
     */
    @RequestMapping(value = "/deleteWorkOrder",method = RequestMethod.POST)
    public Result deleteWorkOrder(@RequestBody WorkOrder workOrder){
        return ResultUtil.success(workOrderService.deleteWorkOrder(workOrder),0);
    }

    @RequestMapping(value = "/isComment/{jobNumber}",method = RequestMethod.GET)
    public Result isComment(@PathVariable String jobNumber){
        return ResultUtil.success(workOrderService.isComment(jobNumber),0);
    }

    @RequestMapping(value = "/isComplaint/{jobNumber}",method = RequestMethod.GET)
    public Result isComplaint(@PathVariable String jobNumber){
        return ResultUtil.success(workOrderService.isComplaint(jobNumber),0);
    }

    @RequestMapping(value = "/isUnderway/{userAccount}",method = RequestMethod.GET)
    public Result isComplaint(@PathVariable Integer userAccount){
        return ResultUtil.success(workOrderService.isUnderway(userAccount),0);
    }




}
